package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.service.SafetyTrainingCardService;
import com.amsp.oa.oademo.vo.SafetyTrainingCardVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "三级安全教育培训卡")
@RestController
@RequestMapping("/api/safety-training-card")
public class SafetyTrainingCardController {

    @Autowired
    private SafetyTrainingCardService safetyTrainingCardService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<IPage<SafetyTrainingCardVO>> getPage(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("姓名") @RequestParam(required = false) String name,
            @ApiParam("班组") @RequestParam(required = false) String team) {
        return Result.ok(safetyTrainingCardService.getPage(current, size, name, team));
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result<SafetyTrainingCardVO> getById(@PathVariable Long id) {
        return Result.ok(safetyTrainingCardService.getById(id));
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public Result<Boolean> saveOrUpdate(@RequestBody @Validated SafetyTrainingCardVO vo) {
        return Result.ok(safetyTrainingCardService.saveOrUpdate(vo));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result<Boolean> removeById(@PathVariable Long id) {
        return Result.ok(safetyTrainingCardService.removeById(id));
    }
} 